﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Net.Chirash.Twitter.TwitterClient;

namespace Net.Chirash.Twitter.TweetZone.WindowComponents
{
    /// <summary>
    /// ErrorMessageProviderで生成される情報に対してバインディング可能にするラッパー。
    /// </summary>
    public class ErrorMessage
        : DependencyObject
    {
        public ErrorMessage()
        {

        }

        #region Provider DependencyProperty

        public static readonly DependencyProperty ProviderDependencyProperty
            = DependencyProperty.Register("Provider", typeof(ErrorMessageProvider), typeof(ErrorMessage),
                                           new PropertyMetadata(new PropertyChangedCallback(ProviderChanged)));
        public ErrorMessageProvider Provider
        {
            get { return GetValue(ProviderDependencyProperty) as ErrorMessageProvider; }
            set { SetValue(ProviderDependencyProperty, value); }
        }

        private static void ProviderChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            string msg = "";
            if (e.NewValue != null)
                msg = (e.NewValue as ErrorMessageProvider).CreateErrorMessage();
            sender.SetValue(MessageDependencyPropertyKey, msg);
        }

        #endregion


        #region Message DependencyProperty

        protected static readonly DependencyPropertyKey MessageDependencyPropertyKey
            = DependencyProperty.RegisterReadOnly("Message", typeof(string), typeof(ErrorMessage), new PropertyMetadata(""));
        public static readonly DependencyProperty MessageDependencyProperty
            = MessageDependencyPropertyKey.DependencyProperty;
        public string Message
        {
            get { return GetValue(MessageDependencyProperty) as string; }
        }

        #endregion
    }
}
